﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace YoUI.Core
{
    /// <summary>
    /// UI遮罩
    /// </summary>
    public class YoMaskMgr
    {

        private static YoMaskMgr _UIMaskMgr;

        public static YoMaskMgr GetUIMask
        {
            get
            {
                if (_UIMaskMgr == null)
                    _UIMaskMgr = new YoMaskMgr();
                return _UIMaskMgr;
            }
        }

        // 遮罩面板
        public Transform _UIMaskPanel;

        public Transform UIMaskPanel
        {
            set
            {
                _UIMaskPanel = value;
            }
        }

        // 显示遮罩
        public void ShowMask(Transform ui, float opacity)
        {


            // 设置遮罩颜色
            _UIMaskPanel.GetComponent<Image>().color = new Color(255, 255, 255, 100);

            _UIMaskPanel.gameObject.SetActive(true);

            // 把遮罩面板移动到最后
            _UIMaskPanel.SetAsLastSibling();

            ui.SetAsLastSibling();

        }

        public void HideMask()
        {
            if (_UIMaskPanel.gameObject.activeInHierarchy)
            {
                _UIMaskPanel.gameObject.SetActive(false);
            }
        }
    }
}
